package model

import (
	"gorm.io/gorm"
	"time"
	"video_08_01/global"
)

type Barrage struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:弹屏ID;primaryKey;not null;" form:"id" json:"id"`                                            // 弹屏ID
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" form:"user_id" json:"user_id"`                                                 // 用户ID
	VideoId   int32          `gorm:"column:video_id;type:int;comment:视频ID;not null;" form:"video_id" json:"video_id"`                                              // 视频ID
	Content   string         `gorm:"column:content;type:varchar(90);comment:内容;not null;" form:"content" json:"content"`                                           // 内容
	Status    int8           `gorm:"column:status;type:tinyint(1);comment:状态  1:展示 2:仅本人可见;not null;default:0;" form:"status" json:"status"`                // 状态  1:展示 2:仅本人可见
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:发送时间;not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"` // 发送时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);comment:修改时间;not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"` // 修改时间
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);comment:删除时间;default:NULL;" form:"deleted_at" json:"deleted_at"`                          // 删除时间
}

func (b *Barrage) TableName() string {
	return "barrage"
}

func (b *Barrage) AddBarrage() error {
	return global.DB.Create(&b).Error
}

func (b *Barrage) DeleteBarrage() error {
	return global.DB.Delete(&b).Error
}

func (b *Barrage) ListBarrage() (barrage []Barrage, err error) {
	err = global.DB.Find(&barrage).Error
	return
}

func (b *Barrage) ListByUserIdBarrage() (barrage []Barrage, err error) {
	err = global.DB.Where("user_id = ?", b.UserId).Find(&barrage).Error
	return
}

func (b *Barrage) ListByHotBarrage(where string) (barrage []Barrage, err error) {
	err = global.DB.Where("content = ?", where).Find(&barrage).Error
	return
}
